﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2012
// admin@franknagl.de
//
namespace SBIP.OptionsForms.NonSBIP
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using Filter;
    using Filter.NonSBIP;

    /// <summary>Filter specified properties form.</summary>
    public partial class NSSimpleLuvColorSegmentationForm : Form
    {
        private readonly Processor processor;
        private readonly NSSimpleLuvColorSegmentation segmentation;

        /// <summary>
        /// Initializes a new instance of the <see cref="NSSimpleColorSegmentationForm"/> class.
        /// </summary>
        /// <param name="processor">The processor.</param>
        public NSSimpleLuvColorSegmentationForm(Processor processor)
        {            
            InitializeComponent();
            this.processor = processor;            
            processor.Filter = new Original();
            segmentation = new NSSimpleLuvColorSegmentation();
        }

        private void TrBarToleranceValueChanged(object sender, EventArgs e)
        {
            segmentation.ColorDistance = trBarColorDistance.Value / 10.0f;
            lbColorDistance.Text = segmentation.ColorDistance.ToString();
        }

        private void BtnProcessClick(object sender, EventArgs e)
        {
            try
            {
                Bitmap b = segmentation.Apply(processor.OriginalBitmap);
                processor.ChangeTexture(b);
            }
            catch(ArgumentException aex)
            {
                MessageBox.Show(aex.Message);
                BtnResetClick(sender, e);
            }
        }

        private void BtnResetClick(object sender, EventArgs e)
        {
            processor.ResetTexture();           
        }
    }
}
